package com.gm.corejava.book2;

import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * User: camark@sina.cn
 * Date: 13-12-27
 * Time: 上午9:54
 */
public class ImageTransferable implements Transferable {

    private Image image;
    public ImageTransferable(Image image) {
        this.image=image;
    }

    @Override
    public DataFlavor[] getTransferDataFlavors() {
        return new DataFlavor[]{DataFlavor.imageFlavor};
    }

    @Override
    public boolean isDataFlavorSupported(DataFlavor flavor) {
        return flavor.equals(DataFlavor.imageFlavor);
    }

    @Override
    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
        if(flavor.equals(DataFlavor.imageFlavor)){
            return image;
        }
        else {
            throw new UnsupportedFlavorException(flavor);
        }
    }
}
